package com.lagou.edu.service.impl;

import com.lagou.edu.dao.TokenDao;
import com.lagou.edu.pojo.Token;
import com.lagou.edu.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

@Service
public class TokenServiceImpl implements TokenService {
    @Autowired
    private TokenDao tokenDao;

    @Override
    public void save(String email, String token) {
        Token record = new Token();
        record.setEmail(email);
        record.setToken(token);
        tokenDao.save(record);
    }

    @Override
    public Token findByToken(String token) {
        Token record = new Token();
        record.setToken(token);
        return tokenDao.findOne(Example.of(record)).get();
    }
}
